package com.rew.canteenbox.activities;

import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import com.rew.canteenbox.R;
import com.rew.canteenbox.bases.AppData;
import com.rew.canteenbox.bases.BaseActivity;
import com.rew.canteenbox.functions.DishesMenuInit;
import com.rew.canteenbox.models.Orders;

import java.util.ArrayList;
import java.util.List;

/**
 *  开始动画效果.
 *
 * Created by HuiWen Ren on 2016/11/10.
 */
public class StartActivity extends BaseActivity{

    private ImageView iv_start;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

        DishesMenuInit dishesMenuInit = new DishesMenuInit();
        AppData appData = (AppData) getApplication();
        appData.setDishesList(dishesMenuInit.getInfo());

        List<Orders> ordersList = new ArrayList<>();
        appData.setOrdersList(ordersList);

        //隐藏标题栏.
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        //隐藏状态栏.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_start);
        initImage();
    }

    private void initImage() {
        iv_start = (ImageView) findViewById(R.id.iv_start);
        iv_start.setImageResource(R.drawable.clouds);

        //进行缩放动画.
        ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.0f, 1.0f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

        scaleAnimation.setDuration(4000);

        //动画播放完成后保持形状.
        scaleAnimation.setFillAfter(true);
        scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                //可以在这里先进行某些操作.
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                MainActivity.inStyle = android.R.anim.fade_in;
                MainActivity.outStyle = android.R.anim.fade_out;
                MainActivity.actionStart(StartActivity.this);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        iv_start.startAnimation(scaleAnimation);
    }
}
